<template>
    <h2>房号修改页面</h2>
    <table border="1">
        <tr>
            <td>房号名称</td>
            <input type="text" v-model="info.trN_Name"/>
        </tr>
        <tr>
            <td>创建时间</td>
            <td>
                <input type="date" v-model="info.trN_Date" />
            </td>
        </tr>
        <tr>
            <td>状态</td>
            <td>
                <input type="radio" v-model="info.trN_State" :value="true"/>上架
                <input type="radio" v-model="info.trN_State" :value="false"/>下架
            </td>
        </tr>
        <tr>
            <td>备注</td>
            <td>
                <textarea v-model="info.trN_Info">

                </textarea>
            </td>
        </tr>
        <tr>
            <input type="button" value="修改" @click="Add"/>
        </tr>
    </table>
</template>
<script setup lang="ts">
    import {ref,onMounted} from 'vue';
    import axios from 'axios';
    import {useRoute,useRouter} from 'vue-router';
    const route=useRoute();
    const router=useRouter();
    import moment from "moment";

    const info=ref({
        trN_Id:route.params.id,
        trN_Name: "",
        trN_Date:"",
        trN_State: true,
        trN_Info: ""
    })

    onMounted(()=>{
        FanTian();
    })

    //反填
    const FanTian=()=>{
        axios.get("https://localhost:7038/api/RoomNumber/FanTian",{
            params:{
                id:route.params.id
            }
        })
        .then(res=>{
            info.value=res.data;
            console.log(info.value.trN_Date.substring(0,10));
            XinDate.value=info.value.trN_Date.substring(0,10);
            info.value.trN_Date=XinDate.value;
        })
        .catch(err=>{
            console.log(err);
        })
    }

    //修改
    const Add=()=>{
        axios.put("https://localhost:7038/api/RoomNumber/UpdateRoomNumber",info.value)
        .then(res=>{
            if(res.data>0){
                alert('修改成功');
                router.push({
                    name:"ShowRoomNumber"
                })
            }
            else{
                alert('修改失败');
            }
        })
        .catch(err=>{
            console.log(err);
        })
    }

    const XinDate=ref("");

    
</script>
